package cn.hist.hfp.converter;

import cn.hist.hfp.entity.BusinessProvider;
import cn.hist.hfp.vo.BusinessProviderVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

@Component
public class BusinessProviderConverter {

    private final
    BusinessConverter businessConverter;

    @Autowired
    public BusinessProviderConverter(BusinessConverter businessConverter) {
        this.businessConverter = businessConverter;
    }

    public BusinessProviderVO convert(BusinessProvider businessProvider) {
        return BusinessProviderVO.builder().city(businessProvider.getCity()).description(businessProvider.getDescription())
                .id(businessProvider.getId()).location(businessProvider.getLocation()).name(businessProvider.getName())
                .businesses(businessConverter.convert(businessProvider.getBusinesses()))
                .phoneNumber(businessProvider.getPhoneNumber()).build();
    }

    public List<BusinessProviderVO> convert(List<BusinessProvider> businessProviders) {
        List<BusinessProviderVO> businessProviderVOS = new ArrayList<>();
        for (BusinessProvider businessProvider: businessProviders) {
            businessProviderVOS.add(convert(businessProvider));
        }
        return businessProviderVOS;
    }

    public Set<BusinessProviderVO> convert(Set<BusinessProvider> businessProviders) {
        Set<BusinessProviderVO> businessProviderVOS = new HashSet<>();
        for (BusinessProvider businessProvider: businessProviders) {
            businessProviderVOS.add(convert(businessProvider));
        }
        return businessProviderVOS;
    }
}
